package com.study.demoservice.aop;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 正则校验手机号
 *
 * @author chenyeqing
 */
public class PhoneNumberValidator implements ConstraintValidator<PhoneNumber, String> {

    public static final String PHONE_REGEX_EXP = "^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[0-9])|(18[0-9])|(19[1,8,9]))\\d{8}$";

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }

        return value.matches(PHONE_REGEX_EXP);
    }
}
